//!此处是容器组件
//!connect是react-redux提供的, 是一个高阶组件 
import { connect } from 'react-redux'
import App from "./App"
// import ReList from './ReList'
import React from "react"
import { BrowserRouter as Router, Route,Link } from 'react-router-dom'


import {
    getMusicList,
    getMusic,
    playOrPause,
    getHot,
    getSearch,
    getMusicId,
    changeShowplaylist,
    getReMusicComment,
    getReMusicList,
    getNowindex,
    changeShowplay,
    setcurrentTime,
    getSingleComment,
    changeCycle,
    getsinglesons,
    setId,
    clearTimenow,
    getTimenow,
    getMusicurl,
    setReturnMsg,
} from './actions'

//*创建映射函数,映射state和dispatch
const mapStateToProps = state => {
    // console.log(state)
    let { 
        list,
        listmusic,
        audio,
        musicId,
        playmusiclist,
        showplaylist,
        Hot,
        SearchBox,
        reList,
        showPlay,
        musicComment,
        listmusicindex,
        currentTime,
        singleComment,
        cycle,
        time,
        musicurl,
        id,
        returnMsg,
    } = state;
    return {
        list,
        listmusic,
        audio,
        musicId,
        playmusiclist,
        showplaylist,
        Hot,
        SearchBox,
        reList,
        musicComment,
        listmusicindex,
        showPlay,
        currentTime,
        singleComment,
        cycle,
        time,
        musicurl,
        id,
        returnMsg,
    }
}
const mapDispatchToProps = dispatch => {
    return {
        //获取榜单
        getlist() {
            dispatch(getMusicList())
        },
        // getlyric() {
        //     dispatch(getlyric())

        // },
        // 热点歌单
        hotRequest() {
            dispatch(getHot())
        },

        // 搜索结果
        searchRequest(msg) {
            dispatch(getSearch(msg))
        },
        // 获取榜单下的页面
        getmusic(id) {
            dispatch(getMusic(id))
        },
        //获取单曲
        getsingle(id) {
            dispatch(getsinglesons(id))
        },
        // 更改当前播放状态
        playOrPause(status) {
            dispatch(playOrPause(status))
        },
        // 获取音乐id
        getMusicId(id) {
            dispatch(getMusicId(id))
        },
        //修改showplaylist
        changeShowplaylist(msg) {
            dispatch(changeShowplaylist(msg))
        },
        //歌单列表
        getReList(url) {
            dispatch(getReMusicList(url))
        },
        //歌单评论
        getComment(url) {
            dispatch(getReMusicComment(url))
        },
        //获取当前播放歌曲的index
        getNowMusicindex(index) {
            dispatch(getNowindex(index))
        },
        //控制播放页面是否出现
        changeShowplay(msg) {
            dispatch(changeShowplay(msg))
        },
        // 设置当前音乐的播放时间
        setcurrentTime(second) {
            dispatch(setcurrentTime(second))
        },
        // 获取单曲音乐评论
        getSingleComment(id){
            dispatch(getSingleComment(id))
        },
        //改变播放模式
        changeCycle(msg) {
            dispatch(changeCycle(msg))
        },
        //获取歌单或歌曲id
        setId(obj) {
            dispatch(setId(obj))
        
        },
        //获取当前已经播放的时长
        getTimenow(msg){
            dispatch(getTimenow(msg))
        },
        //清空当前以播放时长
        clearTimenow(){
            dispatch(clearTimenow())
        },
        //获取当前播放音乐的url
        getMusicURLApi(id){
            dispatch(getMusicurl(id))
        },
        // 设置返回按钮跟随的文本信息
        setReturnMsg(msg){
            dispatch(setReturnMsg(msg))
        },
    }
}

export default connect(mapStateToProps, mapDispatchToProps)(App)

